package com.ruoyi.project.jiaqin.advert.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.advert.domain.JiaqinAdvert;
import com.ruoyi.project.jiaqin.advert.service.IJiaqinAdvertService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 广告列表Controller
 *
 * @author admin
 * @date 2021-01-11
 */
@Controller
@RequestMapping("/jiaqin/advert")
public class JiaqinAdvertController extends BaseController
{
    private String prefix = "jiaqin/advert";

    @Autowired
    private IJiaqinAdvertService jiaqinAdvertService;

    @RequiresPermissions("jiaqin:advert:view")
    @GetMapping()
    public String advert()
    {
        return prefix + "/advert";
    }

    /**
     * 查询广告列表列表
     */
    @RequiresPermissions("jiaqin:advert:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinAdvert jiaqinAdvert)
    {
        startPage();
        List<JiaqinAdvert> list = jiaqinAdvertService.selectJiaqinAdvertList(jiaqinAdvert);
        return getDataTable(list);
    }

    /**
     * 导出广告列表列表
     */
    @RequiresPermissions("jiaqin:advert:export")
    @Log(title = "广告列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinAdvert jiaqinAdvert)
    {
        List<JiaqinAdvert> list = jiaqinAdvertService.selectJiaqinAdvertList(jiaqinAdvert);
        ExcelUtil<JiaqinAdvert> util = new ExcelUtil<JiaqinAdvert>(JiaqinAdvert.class);
        return util.exportExcel(list, "advert");
    }

    /**
     * 新增广告列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告列表
     */
    @RequiresPermissions("jiaqin:advert:add")
    @Log(title = "广告列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinAdvert jiaqinAdvert)
    {
        return toAjax(jiaqinAdvertService.insertJiaqinAdvert(jiaqinAdvert));
    }

    /**
     * 修改广告列表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinAdvert jiaqinAdvert = jiaqinAdvertService.selectJiaqinAdvertById(id);
        mmap.put("jiaqinAdvert", jiaqinAdvert);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告列表
     */
    @RequiresPermissions("jiaqin:advert:edit")
    @Log(title = "广告列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinAdvert jiaqinAdvert)
    {
        System.out.println();
        return toAjax(jiaqinAdvertService.updateJiaqinAdvert(jiaqinAdvert));
    }

    /**
     * 删除广告列表
     */
    @RequiresPermissions("jiaqin:advert:remove")
    @Log(title = "广告列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinAdvertService.deleteJiaqinAdvertByIds(ids));
    }
}
